import math
import tkinter as tk
win = tk.Tk()

# 定义功能函数, event是必须添加的参数，不知道来自哪里


def button_command():
        a=eval(e1.get())
        if(a==1):
            b = "结果是:" + "0"
            la2 = tk.Label(win, text=b, width=20, font=("行楷", 15))
            la2.place(relx=0.2, rely=0.6)
        elif(a==0):
            b="不能输入0!"
            la2 = tk.Label(win, text=b, width=20, font=("行楷", 15))
            la2.place(relx=0.2, rely=0.6)
        else:
            b = "结果是:" + str(math.log(2, a))[:10]
            la2 = tk.Label(win, text=b, width=20, font=("行楷", 15))
            la2.place(relx=0.2, rely=0.6)
def e(event):
    button_command()

# 绑定事件
btn = tk.Button(win, text="计算", command=button_command)
btn.place(relx=0.2, rely=0.4, relwidth=0.5, relheight=0.1)
win.title("log2计算器")
win.bind("<Return>",e)
label1=tk.Label(win,text="log",width=12,font=("楷体",20))
label1.place(x=20,y=50)
label1=tk.Label(win,text="2",width=1,font=("楷体",10))
label1.place(x=130,y=70)

e1=tk.Entry(win)

e1.place(x=140,y=50)

label3=tk.Label(win,text="Designed By CYH",width=1,font=("楷体",10))
label3.place(relx=0.55,rely=0.9,relwidth=0.5)

la2=tk.Label(win,text="结果是:",width=12,font=("行楷",15))
la2.place(relx=0.2,rely=0.6, relwidth=0.5, relheight=0.1)

win.geometry("300x300+200+200")
win.mainloop()

